<!-- 面试查询 -->
<script>
import HPCommonPage from "@/components/HPCommonPage";
import HPTable from "@/components/HPTable";
import HPDialog from '@/components/HPDialog';
import { searchTableColumn } from "../js/cloumn";
import { interviewSearchStatus } from "../js/status";
import { approverOption } from "@/views/interviewManagement/js/status";
import getQuery from '@/utils/mixins/getQuery';
import { remind as remindFetch } from '@/fetch/api'

function fetchInquiriesLists(store, opts) {
  return store.dispatch("GET_INQUIRIES_LISTS", opts);
}
export default {
  mixins: [getQuery],
  created() {
    this.fetchTableData();
  },
  methods: {
    // 推送提醒
    onRemind(row) {
      // remind === 1 ? {originId: interviewId, remindCode: 'remind_02'}  面试反馈提醒
      // remind === 2 ? {originId: orderId, remindCode: 'remind_06'}  面试审批提醒
      const { remind, interviewId, orderId } = row
      remindFetch({
        originId: [interviewId, orderId][remind-1],
        remindCode: ['remind_02', 'remind_06'][remind-1]
      }).then(res => {
        const { state, message } = res.data
        if(state === '0000') {
          this.$message({
            message: message,
            type: 'success',
            duration: 1500,
          });
          this.fetchTableData()
        }
      })
    },
    // * 格式化接口参数
    formatQueryData() {
      const {
        needsCode,
        postCode,
        name,
        createDate,
        status,
        pageCurrent,
        pageSize,
        approvalState,
      } = this.selectData;
      const [interviewDate_b, interviewDate_e] = createDate || [];
      return {
        needsCode,
        postCode,
        name,
        interviewDate_b,
        interviewDate_e,
        status,
        approvalState,
        pageCurrent,
        pageSize,
      };
    },
    // * 获取列表数据
    async fetchTableData() {
      this.isLoad = true;
      this.totals = 0;
      await fetchInquiriesLists(this.$store, this.formatQueryData());
      this.isLoad = false;
      const { state, data } = this.$store.getters.getInquiriesLists;
      if (state === "0000") {
        const { list = [], total, lastPage, pageNum } = data || {};
        this.tableData = list || [];
        this.totals = total;
        if(pageNum > lastPage && lastPage > 0) {
          this.selectData.pageCurrent = lastPage
          this.fetchTableData()
        }
      }
    },
    // * 查询
    onSearch() {
      this.selectData.pageCurrent = 1;
      this.searchData = { ...this.selectData }
      this.fetchTableData();
    },
    // * 查看
    onLookDetail({ needsCvId, state, interview_num }) {
      this.$router.push({
        path: `/selectint/detail/${needsCvId}`,
        query: {
          stus: state,
          num: interview_num,
          formQuery: JSON.stringify(this.searchData),
        },
      });
    },
    // * 切换页条数
    handleSizeChange(val) {
      this.selectData.pageSize = val;
      this.searchData = { ...this.selectData }
      this.onSearch();
    },
    // * 切换页数
    handleCurrentChange(val) {
      this.selectData.pageCurrent = val;
      this.searchData = { ...this.selectData }
      this.fetchTableData();
    },
  },
  data() {
    return {
      selectData: {
        // * 条件查询对象
        status: "",
        postCode: "",
        needsCode: "",
        name: "",
        approvalState: "",
        createDate: [],
        pageCurrent: 1,
        pageSize: 10,
      },
      activeName: "toBeArr",
      statusOptions: interviewSearchStatus,
      tableHeaderItems: searchTableColumn,
      approverStatus: approverOption,
      tableData: [],
      isLoad: false,
      totals: 0,
    };
  },
  components: {
    HPCommonPage,
    HPTable,
    HPDialog,
  },
};
</script>

<template>
  <HPCommonPage :titleText="'面试管理 / 面试查询'">
    <template v-slot:searchForm>
      <el-form :inline="true" :model="selectData" class="form-box res-form-box">
        <el-form-item label="需求单号：">
          <el-input
            v-model="selectData.needsCode"
            clearable
            placeholder="请输入需求单号"
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位名称：">
          <el-input
            v-model="selectData.postCode"
            clearable
            placeholder="请输入岗位名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="姓名：">
          <el-input
            v-model="selectData.name"
            clearable
            placeholder="请输入输入姓名"
          ></el-input>
        </el-form-item>
        <el-form-item label="面试时间：" :class="'date-font-item'">
          <el-date-picker
            v-model="selectData.createDate"
            size="small"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="面试状态：">
          <el-select
            v-model="selectData.status"
            placeholder="请选择面试状态"
            clearable=""
          >
            <template v-for="item in statusOptions">
              <el-option
                v-if="!item.hidden"
                :key="item.key"
                :label="item.label"
                :value="item.key"
              >
              </el-option>
            </template>
          </el-select>
        </el-form-item>
        <el-form-item label="审批状态：">
          <el-select
            v-model="selectData.approvalState"
            placeholder="请选择面试审批状态"
            clearable=""
          >
            <el-option
              v-for="item in approverStatus"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </template>
    <template v-slot:searchFormbtn>
      <el-button type="success" size="small" @click="onSearch">查询</el-button>
    </template>
    <template v-slot:table>
      <HPTable
        :tableHeaderItems="tableHeaderItems"
        :tableData="tableData"
        :loading="isLoad"
      >
      </HPTable>
    </template>
    <template v-slot:pagination>
      <el-pagination
        v-if="totals"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="selectData.pageCurrent"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="selectData.pageSize"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="totals"
      >
      </el-pagination>
    </template>
  </HPCommonPage>
</template>

<style lang="scss"></style>
